clear all
set more off
* set directory 

********************************************************************************
* TABLE 3 -- HETEROGENEITY IN DD ESTIMATES


********************************************************************************
* PANEL A: full sample ownership

local characteristic pct_owned80

use analysis_file,clear

* sample restrictions (note we also drop places treated before charactertistics were observed in 1980)
drop if match_units_flag==1
keep if never_ward==1 | ever_treated==1
drop if pop_flag==1
su mean_units_pc, det
drop if mean_units_pc > `r(p95)'
drop if treatment_year<1980

* estimate characteristic median and make conditional treatment indicator
sum `characteristic' if year==1980,det
gen h_`characteristic'=(`characteristic'>`r(p50)' & `characteristic' !=.)
gen h_a_`characteristic'=h_`characteristic'*after_treatment


reghdfe pc_single after_treatment h_a_`characteristic' ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)
gen in_sample=e(sample)

reghdfe pc_lessSingle after_treatment h_a_`characteristic' if in_sample==1  ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)

reghdfe pc_all after_treatment h_a_`characteristic' if in_sample==1 ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)
	
reghdfe li_ind after_treatment h_a_`characteristic' if in_sample==1  ///
	& year>1986 & year<2016,absorb(id h_`characteristic'#year year) vce(cl statefips)

drop in_sample

********************************************************************************
* PANEL B: full sample income

local characteristic median_hh_income80

use analysis_file,clear
drop if match_units_flag==1
keep if never_ward==1 | ever_treated==1
drop if pop_flag==1
su mean_units_pc, det
drop if mean_units_pc > `r(p95)'
drop if treatment_year<1980

sum `characteristic' if year==1980,det
gen h_`characteristic'=(`characteristic'>`r(p50)' & `characteristic' !=.)
gen h_a_`characteristic'=h_`characteristic'*after_treatment

reghdfe pc_single after_treatment h_a_`characteristic' ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)
gen in_sample=e(sample)

reghdfe pc_lessSingle after_treatment h_a_`characteristic' if in_sample==1  ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)

reghdfe pc_all after_treatment h_a_`characteristic' if in_sample==1 ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)
	
reghdfe li_ind after_treatment h_a_`characteristic' if in_sample==1  ///
	& year>1986 & year<2016,absorb(id h_`characteristic'#year year) vce(cl statefips)

drop in_sample

********************************************************************************
* PANEL C: full sample percent white

local characteristic pct_white80

use analysis_file,clear
drop if match_units_flag==1
keep if never_ward==1 | ever_treated==1
drop if pop_flag==1
su mean_units_pc, det
drop if mean_units_pc > `r(p95)'
drop if treatment_year<1980

sum `characteristic' if year==1980,det
gen h_`characteristic'=(`characteristic'>`r(p50)' & `characteristic' !=.)
gen h_a_`characteristic'=h_`characteristic'*after_treatment

reghdfe pc_single after_treatment h_a_`characteristic' ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)
gen in_sample=e(sample)


reghdfe pc_lessSingle after_treatment h_a_`characteristic' if in_sample==1  ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)

reghdfe pc_all after_treatment h_a_`characteristic' if in_sample==1 ///
	,absorb(id h_`characteristic'#year year) vce(cl statefips)

reghdfe li_ind after_treatment h_a_`characteristic' if in_sample==1  ///
	& year>1986 & year<2016,absorb(id h_`characteristic'#year year) vce(cl statefips)

drop in_sample